import request from '../utils/request.js'
const api={
	 wxlogin:"/shopper/login/wx",
	 shopperreq:"/shopper/req/add",
	 getshopper:"/shopper/req/",
	 getshoperinfo:'/shopper/shoper/get',
	 getlx:'/lx/getall',
	 getproduct:'/clipro/getpro',
	 xiaproduct:"/shopper/prod/xiajia",
	 fabuproduct:"/shopper/prod/fabu",
	 getorder:'/shopper/order/get',
	 getxqproduct:'/shopper/prod/getxq',
	 setorderstatus:'/shopper/order/set'
}
export const wxlogin=(data)=>request({url:api.wxlogin,method:"post",data:{...data}})
export const addshopperreq=({img,...data})=>{
	return new Promise((res,rej)=>{
		      uni.uploadFile({
				  url:'http://127.0.0.1:3006'+api.shopperreq,
				  name:"img",
				  filePath:img,
				  formData:{
					  data:JSON.stringify(data)
				  },
				  success(datas) {
				  	res(JSON.parse(datas.data))
				  },
				  fail(err) {
				  	rej(err)
				  }
			  })
	})
}
export const getshoppers=(userid)=>request({url:api.getshopper+userid})
export const getshoperinfos=(userid)=>request({url:api.getshoperinfo,data:{userid}}) 
export const getgetlxinfos=()=>request({url:api.getlx}) 
export const getgetproductinfos=(shoperid,offset,limit)=>request({url:api.getproduct,data:{shoperid,offset,limit},method:"post"}) 
export const xiaproducts=(id,status)=>request({url:api.xiaproduct,data:{id,status},method:'post'})
export const fabuproducts=({img,...data})=>{
	console.log(img,data)
	return new Promise((res,rej)=>{
		uni.uploadFile({
						  url:'http://127.0.0.1:3006'+api.fabuproduct,
						  name:"img",
						  filePath:img,
						  formData:{
							  data:JSON.stringify(data)
						  },
						  header:{
							  token:uni.getStorageSync("token")
						  },
						  success(datas) {
						  	res(JSON.parse(datas.data))
						  },
						  fail(err) {
						  	rej(err)
						  }
		})
	})
}
export const getorders=(shoperid)=>request({url:api.getorder,data:{shoperid},method:"post"})
export const getxqproductx=(id)=>request({url:api.getxqproduct,data:{id},method:"post"})
export const setorderstatuss=(id,status)=>request({url:api.setorderstatus,data:{id,status},method:"post"})